//
//  AddVisitorViewController.m
//  VisitorFacetestingSystem
//
//  Created by 张斌 on 16/7/7.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//

#import "AddVisitorViewController.h"
#import "AppDelegate.h"
#import "CZNetworkTool.h"
#import "InterFaceDefine.h"
#import "takePhoto.h"
#import "YSDoViewManager.h"
#import "UIView+CZFrame.h"
#import "NSArray+Log.h"

@interface AddVisitorViewController ()<UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UIButton *headimageview;

@property (weak, nonatomic) IBOutlet UITextField *nametext;
@property (weak, nonatomic) IBOutlet UITextField *visitnametext;
@property (weak, nonatomic) IBOutlet UITextField *laifangmuditext;
@property (weak, nonatomic) IBOutlet UITextField *fangwenshichangtext;
@property (weak, nonatomic) IBOutlet UITextField *suoshudanweitext;
@property (weak, nonatomic) IBOutlet UITextField *lianxifangshitext;
@property (weak, nonatomic) IBOutlet UITextField *huanyingyutext;
@property (weak, nonatomic) IBOutlet UIButton *vipbtn;


@end

@implementation AddVisitorViewController
- (IBAction)backbtnclick:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)Vipbtnclick:(UIButton*)sender {
    
    sender.selected = !sender.selected;
}
- (IBAction)headimageviewbtnclick:(id)sender {
    [takePhoto sharePicture:^(UIImage *image) {
        [self.headimageview setImage:image forState:UIControlStateNormal];
    } :^(UIImagePickerController *pickerVc) {
        [self presentViewController:pickerVc animated:YES completion:nil];
    }];
    
}

// 测试选择员工接口
- (void)setting{
    
    [[CZNetworkTool sharedManager] GET:[NSString stringWithFormat:@"%@/c2b367e9-57f4-4280-989f-935f01e3cdca/1",GetEmployeeListByStoreID] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (responseObject) {
            NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            NSLog(@"%@",dict);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
}
- (IBAction)savebtnclick:(id)sender {

    
    // 测试添加访客接口
    NSDictionary* jsondict = @{@"RecordID":@"-1",@"VisitorName":@"访客姓名",@"RespondentID":@"-1",@"Aim":@"来访目的",@"Affilication":@"访客单位",@"ArrivalTimePlan":@"2016-08-01T12:22:32.287972+08:00",@"LeaveTimePlan":@"2016-08-01T12:42:32.287972+08:00",@"WelcomeWord":@"欢迎语",@"Remark":@"备注",@"isVip":@"true",@"StoreID":@"99"};
    
    NSError* error = nil;
    
    NSData * jsonData = [NSJSONSerialization dataWithJSONObject:jsondict options:NSJSONWritingPrettyPrinted error:&error];

    
    NSString * jsonstr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

    
    CZNetworkTool * manager = [CZNetworkTool sharedManager];
    
    [manager POST:AddOneVisitorRecord parameters:@{@"obj":jsonstr} constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        [formData appendPartWithFileData:UIImageJPEGRepresentation(self.headimageview.imageView.image,0.01) name:@"FileData" fileName:@"text.jpg" mimeType:@"image/jpg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, NSData*  _Nullable responseObject) {
        if (responseObject) {
            NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",dict);
        }else {
        NSLog(@"数据为空");

        }
  
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.s
    self.tableView.allowsSelection = NO;
    

}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    [[YSDoViewManager sharedmanager] settoyuanWithview:@[ self.headimageview] andR:self.headimageview.w/2];
}






@end
